/**
 * @author chuzhixin 1204505056@qq.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config/settings'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '监控台',
          icon: 'cookie',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/customerManagement',
    component: Layout,
    redirect: 'customerManagement',
    name: 'CustomerManagement',
    meta: { title: '客户管理', icon: "marker", permissions: ['admin','staff','kefu'] },
    children: [
      {
        path: 'list',
        name: 'CustomerManagementList',
        component: () =>
          import('@/views/customerManagement/index'),
        meta: { title: '客户列表' },
      },
      {
        path: 'manage',
        name: 'CustomerManage',
        component: () =>
          import('@/views/customerManagement/manage'),
        meta: { title: '新增客户' ,permissions: ['admin','staff']},
        
      },
      {
        path: 'depositList',
        name: 'DepositManage',
        component: () =>
          import('@/views/depositManagement/index'),
        meta: { title: '预付款明细表' ,permissions: ['admin','staff']},
        
      }
    ],
  },
  {
    path: '/priceStrategyManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PriceStrategyManagement',
    meta: {
      title: '价格策略管理',
      icon: 'landmark',
      permissions: ['admin','staff'],
    },

    children: [
      {
        path: 'list',
        name: 'PriceStrategyManagementList',
        component: () => import('@/views/priceStrategyManagement/index'),
        meta: {
          title: '价格策略列表',
        },
      },
      {
        path: 'manage',
        name: 'PriceStrategyManage',
        component: () => import('@/views/priceStrategyManagement/manage'),
        meta: {
          title: '新增价格策略',
          noKeepAlive: true,
        },
      },
      {
        path: 'multiManage',
        name: 'MultiPriceStrategyManage',
        component: () => import('@/views/priceStrategyManagement/multiSetting'),
        meta: {
          title: '批量设定价格策略',
          noKeepAlive: false,
        },
      },
      {
        path: 'details',
        name: 'PriceStrategyDetails',
        component: () => import('@/views/priceStrategyManagement/details'),
        meta: {
          title: '价格策略详情',
          noKeepAlive: true,
        },
      }
    ],
  },

  {
    path: '/orderManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'OrderManagement',
    meta: {
      title: '订单管理',
      icon: 'cogs',
      permissions: ['admin','kefu'],
    },

    children: [
      {
        path: '/orderManagement/orders',
        name: 'Orders',
        component: () => import('@/views/orderManagement/index'),
        meta: {
          title: '订单管理',
          icon:'shopping-cart'
        },
      },
    ],
  },

  {
    path: '/sysManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'SysManagement',
    meta: {
      title: '系统管理',
      icon: 'users-cog',
      permissions: ['admin','kefu'],
    },

    children: [

      {
        path: '/usersList',
        name: 'UserList',
        component: () => import('@/views/personnelManagement/userManagement/index'),
        meta: {
          title: '用户管理',
          permissions: ['admin'],
        },
      },
	  {
	    path: '/openidList',
	    name: 'OpenIdList',
	    component: () => import('@/views/useropenid/index'),
	    meta: {
	      title: 'OPENID管理',
	      permissions: ['admin','staff'],
	    },
	  },
      {
        path: '/navigationList',
        name: 'NavigationList',
        component: () => import('@/views/navManagement/index'),
        meta: {
          title: '轮播图管理',
          permissions: ['admin'],
        },
      },
      {
        path: '/informationList',
        name: 'InformationList',
        component: () => import('@/views/infoManagement/index'),
        meta: {
          title: '资讯管理',
          permissions: ['admin'],
        },
      },
      {
        path: '/configList',
        name: 'ConfigList',
        component: () => import('@/views/configManagement/index'),
        meta: {
          title: '系统参数管理',
          permissions: ['admin','kefu'],
        },
      }
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export function resetRouter() {
  router.matcher = new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
